package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 啊滨
 * @date 2023/2/14 14:14
 */
@Mapper
public interface DeliveryAddressMapper {
    /**
     * 根据用户编号查询所属送货地址
     *
     * @param userId
     * @return
     * @throws Exception
     */
    @Select("SELECT * FROM deliveryaddress WHERE userId=#{userId} GROUP BY daId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId);

    /**
     * 根据送货地址编号查询送货地址
     *
     * @param daId
     * @return
     * @throws Exception
     */
    @Select("SELECT * FROM deliveryaddress WHERE daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(Integer daId);

    /**
     * 向送货地址表中添加一条记录
     *
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     * @throws Exception
     */
    @Insert("insert into deliveryaddress(contactName,contactSex,contactTel,address,userId) values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddress(String contactName, Integer contactSex, String contactTel, String address, String userId) ;

    /**
     * 根据送货地址编号更新送货地址信息
     *
     * @param daId
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     * @throws Exception
     */
    @Update("UPDATE deliveryaddress SET contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address},userId=#{userId} WHERE daId=#{daId}")
    public int updateDeliveryAddress(Integer daId, String contactName, Integer contactSex, String contactTel, String address, String userId) ;

    /**
     * 根据送货地址编号删除一条记录
     *
     * @param daId
     * @return
     * @throws Exception
     */
    @Delete("DELETE FROM deliveryaddress WHERE daId=#{daId}")
    public int removeDeliveryAddress(Integer daId);

}
